package c_utils;

import a_entity.Emp;
import b_utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;

public class Test {
    public static void main(String[] args) {
        Connection conn = null;
        Statement sta = null;
        ResultSet rs = null;
        try {
            conn = b_utils.JDBCUtils.getConnection();
            sta = conn.createStatement();
            String sql = "select * from emp";
            rs = sta.executeQuery(sql);

            while (rs.next()) {
                int empon = rs.getInt("empno");
                String ename = rs.getString("ename");
                String job = rs.getString("job");
                int mgr = rs.getInt("mgr");
                Date hiredate = rs.getDate("hiredate");
                Double sal = rs.getDouble("sal");
                Double comm = rs.getDouble("comm");
                int deptno = rs.getInt("deptno");
                Emp emp = new Emp(empon,ename,job,mgr,hiredate,sal,comm,deptno);
                System.out.println(emp);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            JDBCUtils.close(conn,sta,rs);
        }
    }
}
